View Javadoc

1   
2   /*
3    * SmartCrawler
4    *
5    * $Id: AbstractParametrizableComponent.java,v 1.2 2005/08/05 15:55:52 vincool Exp $
6    * Copyright 2005 Davide Pozza
7    *
8    * This program is free software; you can redistribute it
9    * and/or modify it under the terms of the GNU General Public
10   * License as published by the Free Software Foundation;
11   * either version 2 of the License, or (at your option) any
12   * later version.
13   *
14   * This program is distributed in the hope that it will be
15   * useful, but WITHOUT ANY WARRANTY; without even the implied
16   * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17   * PURPOSE. See the GNU General Public License for more
18   * details.
19   *
20   * You should have received a copy of the GNU General Public
21   * License along with this program; if not, write to the Free
22   * Software Foundation, Inc., 59 Temple Place, Suite 330,
23   * Boston, MA 02111-1307 USA
24   *
25   */
26  
27  package org.smartcrawler.common;
28  
29  import java.util.Hashtable;
30  import java.util.StringTokenizer;
31  import org.apache.log4j.Logger;
32  
33  /***
34   *
35   *
36   * @author <a href="mailto:pozzad@alice.it">Davide Pozza</a>
37   * @version <tt>$Revision: 1.2 $</tt>
38   */
39  public class AbstractParametrizableComponent {
40  
41      private Hashtable<String, String> parameters = new Hashtable<String, String>();
42      private static Logger log = SCLogger.getLogger(AbstractParametrizableComponent.class);
43  
44      /***
45       * Creates a new instance of AbstractParametrizableComponent
46       */
47      public AbstractParametrizableComponent() {
48      }
49  
50      /***
51       *
52       * @param name
53       * @return
54       */
55      public String[] getParameters(String name) {
56          //return parameters.get(name).split("[//s]*");
57          String links = parameters.get(name);
58          StringTokenizer stk = new StringTokenizer(links);
59          String[] res = new String[stk.countTokens()];
60          int i = 0;
61          while(stk.hasMoreTokens()) {
62              String tok = stk.nextToken().trim();
63              if (tok.length() > 0) {
64                  res[i++] = tok;
65              }
66          }
67          return res;
68  
69      }
70  
71      /***
72       *
73       * @param name
74       * @return
75       */
76      public String getParameter(String name) {
77          if (parameters.containsKey(name)) {
78              return parameters.get(name);
79          } else {
80              log.warn("Parameter " + name + " not found.");
81              return null;
82          }
83      }
84  
85      /***
86       *
87       * @param parameters
88       */
89      public void setParameters(Hashtable parameters) {
90          this.parameters = parameters;
91      }
92  }